package com.example.exception;

import com.example.model.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @author hello
 * @date 2023-04-12 15:56:24
 */
@RestControllerAdvice
@Component
@Slf4j
public class BusinessExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ApiResponse<String> businessExceptionHandler(BusinessException e) {
        log.error("BusinessException：", e);
        return ApiResponse.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ApiResponse<String> runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException：", e);
        return ApiResponse.error();
    }

    @ExceptionHandler(Exception.class)
    public ApiResponse<String> exceptionHandler(Exception e) {
        log.error("Exception：", e);
        return ApiResponse.error();
    }


}
